using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Stickerwall.WebApp;

var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

Console.WriteLine($"Current Environment: {builder.HostEnvironment.Environment}");
Console.WriteLine($"Current BaseAddress: {builder.HostEnvironment.BaseAddress}");

builder.Services.AddTransient<StickerwallMessageHandler>();

if (builder.HostEnvironment.IsDevelopment())
{
    builder.Services.AddHttpClient("stickerwall", client => client.BaseAddress = new Uri("http://localhost:5182/"))
        .AddHttpMessageHandler<StickerwallMessageHandler>();
}
else
{
    builder.Services.AddHttpClient("stickerwall",
            client => client.BaseAddress = new Uri(new Uri(builder.HostEnvironment.BaseAddress), "api/"))
        .AddHttpMessageHandler<StickerwallMessageHandler>();
}

builder.Services.AddOidcAuthentication(options =>
{
    // Configure your authentication provider options here.
    // For more information, see https://aka.ms/blazor-standalone-auth
    builder.Configuration.Bind("Local", options.ProviderOptions);
});

builder.Services.AddBlazorBootstrap();

await builder.Build().RunAsync();
